package c1760;

import java.util.*;
 
public class H {
    public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		//TODO
		int  T=cin.nextInt();
		while(T-->0){
		    for(char c:cin.next().toCharArray()){
		        if(Character.isLowerCase(c)){
		            System.out.print(Character.toUpperCase(c));
		        }else{
		            System.out.print(Character.toLowerCase(c));
		        }
		    }
		    System.out.println();
		}
		cin.close();
	}
}